package org.weasel.views;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.part.ViewPart;
import org.weasel.business.Project;
import org.weasel.controllers.ProjectViewController;

public class ProjectDetail extends ViewPart {

	public static final String ID = "org.weasel.views.ProjectDetail"; // TODO
																		// Needs
																		// to be
																		// whatever
																		// is
																		// mentioned
																		// in
																		// plugin.xml

	private Composite top = null;

	private Label lbl_name = null;

	private Text txt_name = null;

	private Label lbl_notes = null;

	private Text txtArea_notes = null;
	private ProjectViewController controller;

	private DeveloperComposite developerComposite = null;

	private Text txtStartDate = null;

	private Label lblStartDate = null;

	private Text txtEndDate = null;

	private Label lblEndDate = null;

	private BurndownChartComposite chartComposite;
	private TimeChartComposite timeChartComposite;

	@Override
	public void createPartControl(Composite parent) {
		// TODO Auto-generated method stub
		top = new Composite(parent, SWT.NONE);
		top.setLayout(null);
		top.addDisposeListener(new org.eclipse.swt.events.DisposeListener() {
			public void widgetDisposed(org.eclipse.swt.events.DisposeEvent e) {
				controller.doViewClosedActions();
			}
		});
		lbl_name = new Label(top, SWT.LEFT);
		lbl_name.setText("Name:");
		lbl_name.setBounds(new Rectangle(15, 15, 36, 16));
		txt_name = new Text(top, SWT.BORDER);
		txt_name.setBounds(new Rectangle(60, 15, 286, 19));
		txt_name.addFocusListener(new org.eclipse.swt.events.FocusAdapter() {
			public void focusLost(org.eclipse.swt.events.FocusEvent e) {
				controller.setProjectName(txt_name.getText());
			}
		});
		lbl_notes = new Label(top, SWT.NONE);
		lbl_notes.setBounds(new Rectangle(15, 45, 33, 13));
		lbl_notes.setText("Notes:");
		txtArea_notes = new Text(top, SWT.MULTI | SWT.WRAP | SWT.V_SCROLL
				| SWT.BORDER);
		txtArea_notes.setBounds(new Rectangle(60, 45, 646, 166));
		txtArea_notes
				.addFocusListener(new org.eclipse.swt.events.FocusAdapter() {
					public void focusLost(org.eclipse.swt.events.FocusEvent e) {
						controller.setNotes(txtArea_notes.getText());
					}
				});
		txtStartDate = new Text(top, SWT.BORDER);
		txtStartDate.setBounds(new Rectangle(424, 15, 100, 19));
		txtStartDate
				.addFocusListener(new org.eclipse.swt.events.FocusAdapter() {
					public void focusLost(org.eclipse.swt.events.FocusEvent e) {
						controller.setProjectStartDate(txtStartDate.getText());
						controller.calculateDates();
					}
				});
		lblStartDate = new Label(top, SWT.LEFT);
		lblStartDate.setBounds(new Rectangle(360, 16, 61, 18));
		lblStartDate.setText("Start-date:");
		txtEndDate = new Text(top, SWT.BORDER);
		txtEndDate.setBounds(new Rectangle(602, 15, 100, 19));
		txtEndDate.setEditable(false);
		lblEndDate = new Label(top, SWT.LEFT);
		lblEndDate.setBounds(new Rectangle(541, 16, 55, 16));
		lblEndDate.setText("End-date:");

		controller = ProjectViewController.instance();
		developerComposite = controller.createDeveloperComposite(top, SWT.NONE);
		developerComposite.setBounds(new Rectangle(65, 227, 643, 170));
		
		chartComposite = controller.createBurndownchartComposite(top, SWT.NONE);
		chartComposite.setBounds(new Rectangle(65,400, 500, 320));
		
		timeChartComposite = controller.createTimeChartComposite(top, SWT.NONE);
		timeChartComposite.setBounds(new Rectangle(567,400, 500, 320));
	}

	@Override
	public void setFocus() {
		// TODO Auto-generated method stub

	}

	public void showProjectInformation(Project project) {
		this.setPartName(project.getName());
		txt_name.setText(project.getName());
		txtArea_notes.setText(project.getNotes());
		if(project.getStartDate()!=null)
			txtStartDate.setText(project.getStartDate());
		if (project.getEndDate() != null) {
			txtEndDate.setText(project.getEndDate());
		}
	}

	public void setEndDate(String date) {
		txtEndDate.setText(date);
	}

} // @jve:decl-index=0:visual-constraint="10,10,730,763"
